<!--
 * @Author: Meow
 * @Date: 2019-10-10 20:22:47
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2019-10-21 10:08:11
 * @Description: 标签管理
 -->
<template>
  <dictionaryTableView :tableData="tableData"
                       :page="page"
                       :selectList="selectList"
                       @changePage="changePage"
                       @sizeChange="sizeChange"
                       @deleteTableList="deleteTableList"
                       @deleteTableAll="deleteTableAll"
                       @search="search"
                       @onSubmitForm="onSubmitForm"></dictionaryTableView>
</template>

<script>
import dictionaryTableView from "./DictionaryTableView"
import moreUseApi from "@/httpUtils/MoreUse/moreUse"
export default {
  name: "SystemLog",
  components: {
    dictionaryTableView
  },
  filters: {},
  computed: {},
  data () {
    return {
      page: {
        pageNum: 1,//  当前页
        pageSize: 5,//  每页几条
        total: 8,
        typeName: ''
      },
      tableData: [],
      selectList: []
    };
  },
  watch: {
    page: {
      handler (newName, oldName) {
        moreUseApi.findAllDictTypeInfo(this.page).then(res => {
          this.tableData = res.data.data.list
          this.page.pageNum = res.data.data.pageNum
          this.page.pageSize = res.data.data.pageSize
          this.page.total = res.data.data.total
        })
      },
      immediate: true,
      deep: true
    }
  },
  created () {
    //  获取分页数据

  },
  mounted () {

  },
  methods: {
    //  搜索框输入
    remoteMethod (query) {
      console.log(query);
      if (query !== "") {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;
          this.options = this.list.filter(item => {
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        }, 200);
      } else {
        this.options = [];
      }
    },
    //  搜索框选中
    selectValue (value) {
      console.log(value);
      this.value = value;
    },
    //  点击分页按钮
    changePage (pageNum) {
      console.log(pageNum)
      this.page.pageNum = pageNum
    },
    //  切换页数
    sizeChange (pageSize) {
      this.page.pageSize = pageSize
    },
    //  点击删除按钮
    deleteTableList (data) {
      console.log(data)
      moreUseApi.deleteDictTypeById({ id: data.id }).then(res => {
        if (res.data.code === 200) {
          this.$message.success('删除成功')
          moreUseApi.findAllDictTypeInfo(this.page).then(res => {
            this.tableData = res.data.data.list
            this.page.pageNum = res.data.data.pageNum
            this.page.pageSize = res.data.data.pageSize
            this.page.total = res.data.data.total
          })
        } else {
          this.$message.error('服务器错误')
        }
      })
    },
    //  多删
    deleteTableAll (data) {
      console.log(data)
      data.forEach((item, index, arr) => {
        moreUseApi.deleteDictTypeById({ id: item.id }).then(res => {
        })
      })
      moreUseApi.findAllDictTypeInfo(this.page).then(res => {
        this.tableData = res.data.data.list
        this.page.pageNum = res.data.data.pageNum
        this.page.pageSize = res.data.data.pageSize
        this.page.total = res.data.data.total
      })
      this.$message.success('删除成功')
    },
    //  点击搜索按钮
    search (data) {
      console.log(data)
      this.page.typeName = data
    },
    //  表单点击确定按钮
    onSubmitForm (data) {
      moreUseApi.addDictType(data).then(res => {
        if (res.data.code === 200) {
          this.$message.success(res.data.message)
          moreUseApi.findAllDictTypeInfo(this.page).then(res => {
            this.tableData = res.data.data.list
            this.page.pageNum = res.data.data.pageNum
            this.page.pageSize = res.data.data.pageSize
            this.page.total = res.data.data.total
          })
        } else {
          this.$message.error('服务器错误')
        }
      })
    }

  },
  destroyed () { }
};
</script>

<style scoped lang="less">
.homeLogic {
  width: 100%;
  height: 100%;
}
</style>
